// devops/pages/apply/apply.js
import service from '../../../utils/request'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    steps: [
      {
        text: '提交申请',
        desc: '',
        activeIcon: 'success',
      },
      {
        text: '审核',
        desc: '',
        activeIcon: 'success',
      },
      {
        text: '预约安装中',
        desc: '',
        activeIcon: 'success',
      },
      {
        text: '安装中',
        desc: '',
        activeIcon: 'success',
      },
      {
        text: '安装完成',
        desc: '',
        activeIcon: 'checked',
      },
    ],
    id:'',
    info: {
      state: 2
    },
    color: '#07c160',
    active: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      id: options.id
    })
    // this.getQuery()
  },

  //详情 
  getQuery(){
    let that  =this
      service("POST","/personal/apply/list",{}).then(res => {
        console.log('列表', res)
        if(res.data.code == 414){
          this.isLogin()
          return
        }
        if(res.data.code ==0){
          let data = res.data.page.list
          data.map(item => {
            item.minintus = 0
            if(item.beginTime){
              if(item.endTime){
               item.minintus = Math.abs(new Date(item.endTime) -new Date(item.beginTime))/1000/60
              }else{
                item.minintus =Math.abs(new Date() -new Date(item.beginTime))/1000/60
              }
            }
            return item
          })
          if(res.data.page.list.length>0){
            let state = res.data.page.list[0].state
            let steps= [
              {
                text: '提交申请',
                desc: '',
                activeIcon: 'success',
              },
              {
                text: '审核',
                desc: '',
                activeIcon: 'success',
              },
              {
                text: '预约安装中',
                desc: '',
                activeIcon: 'success',
              },
              {
                text: '安装中',
                desc: '',
                activeIcon: 'success',
              },
              {
                text: '安装完成',
                desc: '',
                activeIcon: 'checked',
              },
            ]
            let active = 0
            if(state ==0 || state == 1){
              active = 0
            }else if(state == 2){
              active = 2
            }else if(state == 3){
              active = 3
            }else if(state == 4){
              active = 4
            }else if(state ==6){
              active = 1
              steps[1].activeIcon = 'fail'
              steps[1].name = '审核失败'
            }else{
              active = 3
              steps[1].name = '安装失败'
              steps[3].activeIcon = 'fail'
            }
            that.setData({
              info: res.data.page.list[0],
              active: active
            })
          }
          
        }
      })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})